package DB;

import Models.User;
import Interfaces.IUser;
import Exceptions.DaoException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class GetUser_DB implements IUser{
   
    public GetUser_DB(){
    
    }
    
    @Override
   public User SearchUser(String Username)
    {   
        //init
        Connection conn=null;
        try {
            conn=javaconnect.ConnecrDb("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/nlr");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(GetUser_DB.class.getName()).log(Level.SEVERE, null, ex);
        }
        User x;
        x=new User();
        if(conn!=null)
        {
        ResultSet rs;
        rs=null;
        PreparedStatement pst;
        pst = null;
        
        String sql;
        sql = "select * from  user where username=? ";
        try {
            pst = conn.prepareStatement(sql);
            pst.setString(1, Username);
            
           
            
            rs = pst.executeQuery();
            if (rs.next()) {
                x.setName(rs.getString("name"));
                x.setSurname(rs.getString("surname"));
                x.setPass(rs.getString("pass"));
                x.setPhone(rs.getString("phone"));
                x.setUsername(rs.getString("username"));
                x.setEmail(rs.getString("email"));
                x.setNOShops(rs.getString("noshop"));
              
           
                //TODO put code to transfer to next Frame
            }   
        } catch (SQLException e) {
           return x;
        }
        
        return x;
    } else
   {
       return x;
   }
    }
  

    
}
